package com.spring.demo7.eg4;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;

import java.util.Map;

/**
 * @author vhans
 */
@ComponentScan
public class Test {
    @org.junit.Test
    public void test1() {
        System.out.println("准备启动spring容器");
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Test.class);
        System.out.println("spring容器启动完毕");

        System.out.println("开始使用service1");
        System.out.println(context.getBean(Service1.class));
    }

    @org.junit.Test
    public void test2() {
        System.out.println("准备启动spring容器");
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(MainConfig3.class);
        System.out.println("spring容器启动完毕");

        System.out.println("开始使用name和address");
        Map<String, String> beansOfType = context.getBeansOfType(String.class);
        beansOfType.forEach((name, bean) -> {
            System.out.println(name + "->" + bean);
        });
    }
}
